include ./py/mkenv.mk

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h

# MicroPython feature configurations
MICROPY_ROM_TEXT_COMPRESSION ?= 1

# include py core make definitions
include $(TOP)/py/py.mk

CROSS_COMPILE ?= /home/harmony/gcc_riscv32/bin/riscv32-unknown-elf-

INC += -I.
INC += -I$(TOP)
INC += -I$(BUILD)

DFU = $(TOP)/tools/dfu.py
PYDFU = $(TOP)/tools/pydfu.py
CFLAGS = $(INC) -Wall -Werror -std=c99  
ARFLAGS = rc

CSUPEROPT = -Os # save some code space

CFLAGS += -Os -DNDEBUG
CFLAGS += -fdata-sections -ffunction-sections

LIBS =

SRC_C = \
	dtpython.c \
	uart_core.c \
	lib/utils/printf.c \
	lib/utils/stdout_helpers.c \
	lib/utils/pyexec.c \
	$(BUILD)/_frozen_mpy.c \

OBJ = $(PY_CORE_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))

all: $(BUILD)/libdtpython.a

$(BUILD)/_frozen_mpy.c: frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h
	$(ECHO) "MISC freezing bytecode"
	$(Q)$(TOP)/tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@

$(BUILD)/libdtpython.a: $(OBJ)
	$(ECHO) "ARCHIVE $@"
	$(Q)$(AR) $(ARFLAGS) -o $@ $^ $(LIBS)
	$(ECHO) "Success! Target ==> $@"

include $(TOP)/py/mkrules.mk
